										
package com.module.device.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import base.util.Page;

import com.module.device.manager.DeviceBreakdownManager;
import com.module.device.manager.DeviceLifecycleManager;
import com.module.device.vo.DeviceBreakdown;
import com.module.device.vo.DeviceLifecycle;

public class DeviceBreakdownService {

	public Page list(DeviceBreakdown bean, Integer start, Integer limit)
			throws Exception {
		Page page = new Page();
		page.setStart(start);
		page.setLimit(limit);
		//bean.setUserId(LoginSession.getUserid());
		DeviceBreakdownManager manager = DeviceBreakdownManager.getInstance();
		page = manager.list(page, bean);
		List list = page.getRows();
		for(int i=0;i<list.size();i++)
		{
			DeviceBreakdown dbd=(DeviceBreakdown) list.get(i);
			System.out.print("======="+dbd.getDeviceType());
		}
		return page;
	}

	public Map<String,Object> remove(Long id)throws Exception{       
		Map<String,Object> map = new HashMap<String,Object>();
		DeviceBreakdownManager manager = DeviceBreakdownManager.getInstance();
		map = manager.delete(id);
		return map;
		
	}	


	public Map<String,Object> save(DeviceBreakdown bean)throws Exception{
		//bean.setOrgId(LoginSession.getOrgid());
		Map<String,Object> map = new HashMap<String,Object>();
		DeviceBreakdownManager manager = DeviceBreakdownManager.getInstance();
		System.out.println("设备是否停用");
		map = manager.add(bean);
		DeviceLifecycleManager manager1 = DeviceLifecycleManager.getInstance();
		DeviceLifecycle bean1 = manager1.findById(bean.getLifecycleId());
		
		if(!bean1.getLifecycleStatus().equals(bean.getDeviceStatus()))
		{
			bean1.setLifecycleStatus(bean.getDeviceStatus());
			manager1.add(bean1);
		}
		return map;

	} 
	

	public DeviceBreakdown findById(Long id)throws Exception{
		DeviceBreakdown bean = new DeviceBreakdown();
		DeviceBreakdownManager manager = DeviceBreakdownManager.getInstance();
		bean = manager.findById(id);
		return bean;
	}
	
	public Page findByDeviceTypeName(String deviceTypeName, Integer start, Integer limit)
	throws Exception {
	Page page = new Page();
	page.setStart(start);
	page.setLimit(limit);
	DeviceBreakdownManager manager = DeviceBreakdownManager.getInstance();
	page = manager.findByDeviceTypeName(page, deviceTypeName);
	List list = page.getRows();
	for(int i=0;i<list.size();i++)
	{
		DeviceBreakdown dbd=(DeviceBreakdown) list.get(i);
		System.out.print("======="+dbd.getDeviceEntity().getDeviceType().getDeviceTypeName());
	}
	return page;
	}
	
	public static void main(String rags[]) throws Exception
	{
		DeviceBreakdown bean = new DeviceBreakdown();
		bean.setDeviceType("PDA");
		bean.setDeviceCode("00851");
		bean.setSoftwareCode("00851");
		bean.setLifecycleId(1L);
		bean.setDescribe("2222222222");
		bean.setDeviceStatus("N");
		//bean.setSearchDeviceTypeName("PDA");
		DeviceBreakdownService dbs = new DeviceBreakdownService();
		//dbs.list(bean, 0, 10);
		//dbs.findByDeviceTypeName("PDA", 0, 10);
		dbs.save(bean);
	}

}
